*This Stata do-file replicates Figure 3 in Patrick J. Egan and Megan Mullin, "US Partisan Polarization on Climate Change: Can Stalemate Give Way to Opportunity?" forthcoming in PS: Political Science and Politics.

*this do-file last updated May 29, 2023.

*data not archived per terms of use; see "README.txt" in this replication archive for details.


clear all
set more off


import delimited countypres_2000-2020.csv
keep if year==2020
keep if party=="REPUBLICAN"
collapse (first) year state_po county_name candidate party totalvotes (sum) candidatevotes, by(county_fips)
gen reppct=candidatevotes/totalvotes*100
save countypresvote2020.dta, replace

clear
import delimited fsf_flood_county_summary.csv
save fsf_flood_county_summary.dta, replace

clear
import delimited fsf_fire_county_summary.csv
save fsf_fire_county_summary.dta, replace

clear
import delimited heat_v1.1_summary_fsf_heat_county_summary.csv
save heat_v1.1_summary_fsf_heat_county_summary.dta, replace

clear
import delimited nhgis0013_ds248_2020_county.csv
save census2020county.dta, replace

clear
use countypresvote2020.dta
rename county_fips fips
replace fips=11001 if state_po=="DC"
merge 1:1 fips using fsf_flood_county_summary.dta, keepusing(count_property avg_risk_score_all count_floodfactor7 count_floodfactor8 count_floodfactor9 count_floodfactor10)
rename count_property count_property_flood
rename avg_risk_score_all avg_risk_score_flood
drop if _merge==2   
drop _merge
merge 1:1 fips using fsf_fire_county_summary.dta, keepusing(count_property avg_risk_score_all count_firefactor7 count_firefactor8 count_firefactor9 count_firefactor10)
rename count_property count_property_fire
rename avg_risk_score_all avg_risk_score_fire
drop _merge
merge 1:1 fips using heat_v1.1_summary_fsf_heat_county_summary.dta, keepusing(count_property count_heatfactor7 count_heatfactor8 count_heatfactor9 count_heatfactor10)
rename count_property count_property_heat
drop _merge
rename fips geocode
merge 1:1 geocode using census2020county.dta, keepusing(u7b001)
drop if _merge==2
drop _merge
rename geocode fips
rename u7b001 pop2020
save countyrisk.dta, replace

gen pctfloodfact7pl=(count_floodfactor7+ count_floodfactor8+ count_floodfactor9+ count_floodfactor10)/count_property_flood*100
gen pctfirefact7pl=(count_firefactor7+ count_firefactor8+ count_firefactor9+ count_firefactor10)/count_property_fire*100
gen pctheatfact7pl=(count_heatfactor7+ count_heatfactor8+ count_heatfactor9+ count_heatfactor10)/count_property_heat*100
save countyrisk.dta, replace


* weighted regressions *
* omit AK and HI; AK has geography mismatch, both not included for Fire and Heat Factor * 

reg reppct pctfloodfact7pl [aweight= pop2020] if state_po~="HI" & state_po~="AK"
reg reppct pctfirefact7pl [aweight= pop2020] if state_po~="HI" & state_po~="AK"
reg reppct pctheatfact7pl [aweight= pop2020] if state_po~="HI" & state_po~="AK"


* figure *
use countyrisk.dta
keep if state_po~="HI" & state_po~="AK"

twoway (scatter reppct pctfloodfact7pl, mc(gs14) msize(vsmall)) (lowess reppct pctfloodfact7pl, lcolor(black) lwidth(medthick)) (lfit reppct pctfloodfact7pl [aweight=pop2020], lcolor(black) lwidth(medthin) lpattern(dash)), xtitle("% at severe or extreme risk", margin(medium)) ylabel(, angle(horizontal)) ytitle("% Republican vote") legend(order(2 "lowess" 3 "linear fit, population-weighted") col(1) region(lstyle(none)) size(*.8)) title("{bf: County flood risk}") text(82 70 "{bf: b = .385*}", size(medsmall) placement(east)) plotregion(style(none))
graph save floodrisk, replace

twoway (scatter reppct pctfirefact7pl, mc(gs14) msize(vsmall)) (lowess reppct pctfirefact7pl, lcolor(black) lwidth(medthick)) (lfit reppct pctfirefact7pl [aweight=pop2020], lcolor(black) lwidth(medthin) lpattern(dash)), xtitle("% at severe or extreme risk", margin(medium)) ylabel(, angle(horizontal)) ytitle("% Republican vote") legend(off) title("{bf: County fire risk}") text(61 70 "{bf: b = .278*}", size(medsmall) placement(east)) plotregion(style(none)) 
graph save firerisk, replace

twoway (scatter reppct pctheatfact7pl, mc(gs14) msize(vsmall)) (lowess reppct pctheatfact7pl, lcolor(black) lwidth(medthick)) (lfit reppct pctheatfact7pl [aweight=pop2020], lcolor(black) lwidth(medthin) lpattern(dash)), xtitle("% at severe or extreme risk", margin(medium)) ylabel(, angle(horizontal)) ytitle("% Republican vote") legend(off) title("{bf: County heat risk}") text(42 70 "{bf: b = .002}", size(medsmall) placement(east)) plotregion(style(none)) 
graph save heatrisk, replace

grc1leg floodrisk.gph firerisk.gph heatrisk.gph, legendfrom(floodrisk.gph) row(1) name(countyrisk, replace)
graph display countyrisk, ysize(4) xsize(10)
graph export countyrisk.png, replace



